using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DownloadDocumentsBL;
using Microsoft.SharePoint;
using System.IO;

namespace DownloadAllDocumentsWeb
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string listId = Request.Params["listId"];
            //string returnUrl = Request.Params["returnUrl"];

            if (listId != null )
            {
                SPWeb web = SPContext.Current.Web;
                if (web.Lists[new Guid(listId)].GetType() == typeof(Microsoft.SharePoint.SPDocumentLibrary))
                {
                    SPDocumentLibrary doclib = (SPDocumentLibrary)web.Lists[new Guid(listId)];
                    ZipDocuments zipDocs = new ZipDocuments(doclib);
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + doclib.Title + ".zip");
                    
                    Response.ContentType = "application/octet-stream";               
                    zipDocs.CreateZip(Response.OutputStream);
                    
                }
            }
            
        }
    }
}
